package com.example.controller;

import com.example.domain.dto.CommentDto;
import com.example.domain.dto.CommentQuery;
import com.example.domain.po.Comment;
import com.example.domain.response.HttpResponse;
import com.example.domain.response.PageResult;
import com.example.domain.vo.CommentVo;
import com.example.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/comment")
public class CommentController {
    private final CommentService commentService;

    @PostMapping("/add")
    public HttpResponse addComment(@RequestBody CommentDto commentDto) {
        Integer count = commentService.addComment(commentDto);
        if (count > 0){
            return HttpResponse.success();
        }
        return HttpResponse.error("添加失败");
    }

    /**
     * 分页查询评论
     * @param commentQuery
     * @return
     */
    @GetMapping("/pageQuery")
    public HttpResponse<PageResult<CommentVo>> pageQuery(CommentQuery commentQuery) {

        return HttpResponse.success(commentService.pageQuery(commentQuery));
    }



}
